Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

smr15.js ➔ recalcOnKeyUp   A
last analyzed

Complexity

Conditions 4

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
(function() {
2
"use strict";
3
4
	window.voteSite = function(snUrl) {
5
		// Must not redirect the current page until after the external vote
6
		// site URL has been opened in a new tab. Use setTimeout to do this.
7
		setTimeout(function() {
8
			window.location = snUrl;
9
		}, 0);
10
	};
11
12
	function doCalc(type, totalDest) {
13
		var df = document.FORM;
14
		var inputs = df.querySelectorAll('input[name*="' + type + '"]');
15
		var total = 0;
16
		inputs.forEach(function(input) {
17
			total += Number(input.value);
18
		});
19
		df[totalDest].value = total;
20
	};
21
22
	// Recalculate total number of ports, summing over level
23
	window.levelCalc = function() {
24
		doCalc('port', 'totalLevel');
25
	};
26
27
	// Recalculate sum of port race percentages
28
	window.raceCalc = function() {
29
		doCalc('race', 'totalRace');
30
	};
31
32
	// Set the total number of ports to zero
33
	window.setZero = function() {
34
		var df = document.FORM;
35
		var inputs = df.querySelectorAll('input[name*="port"]');
36
		inputs.forEach(function(input) {
37
			input.value = 0;
38
		});
39
		df.totalLevel.value = 0;
40
	};
41
42
	// Set the port race distribution to be equal
43
	window.setEqual = function() {
44
		var df = document.FORM;
45
		var inputs = df.querySelectorAll('input[name*="race"]');
46
		var baseValue = Math.floor(100 / inputs.length);
47
		var leftover = 100 - inputs.length * baseValue;
48
		inputs.forEach(function(input) {
49
			if (leftover > 0) {
50
				input.value = baseValue + 1;
51
				leftover -= 1;
52
			} else {
53
				input.value = baseValue;
54
			}
55
		});
56
		df.totalRace.value = 100;
57
	};
58
59
	var body, currentlyFlashing=false, flashColour, origColour, intervalFlash, timeoutStopFlash;
60
61
	function stopFlash() {
62
		clearInterval(intervalFlash);
63
		body.style.backgroundColor = origColour;
0 ignored issues
show
Bug introduced by
The variable body seems to be never initialized.
Loading history...
64
		currentlyFlashing = false;
65
	};
66
67
	function bgFlash() {
68
		var body = document.getElementsByTagName('body')[0];
69
		if(body.style.backgroundColor === origColour) {
70
			body.style.backgroundColor = flashColour;
71
		}
72
		else {
73
			body.style.backgroundColor = origColour;
74
		}
75
	};
76
77
	window.triggerAttackBlink = function(colour) {
78
		if(origColour == null) {
0 ignored issues
show
Best Practice introduced by
Comparing origColour to null using the == operator is not safe. Consider using === instead.
Loading history...
79
			origColour = document.getElementsByTagName('body')[0].style.backgroundColor;
80
		}
81
		flashColour = '#'+colour;
82
		clearTimeout(timeoutStopFlash);
83
		if (currentlyFlashing === false) {
84
			currentlyFlashing = true;
85
			//flash 3 times
86
			bgFlash();
87
			intervalFlash = setInterval(bgFlash,500);
88
		}
89
		timeoutStopFlash = setTimeout(stopFlash,3500);
90
	};
91
})();
92
93
// Used by shop_hardware.php
94
function recalcOnKeyUp(transaction, hardwareTypeID, cost) {
95
	var form = document.getElementById(transaction + hardwareTypeID);
96
	form.total.value = form.amount.value * cost;
97
}
98
99
// Used by planet_defense.php
100
function showWeaponInfo(select) {
101
	var target = $(select).data('target');
102
	var show = $("option:selected", select).data('show');
103
	$(target).children().addClass('hide');
104
	$(show).removeClass('hide');
105
}
106
107
// Used by game_join.php
108
function showRaceInfo(select) {
109
	var race_id = $("option:selected", select).val();
110
	document.getElementById('race_image').src = "images/race/race" + race_id + ".jpg";
111
	var desc = document.getElementById('race_descr');
112
	$(desc).children().addClass('hide');
113
	$(".race_descr" + race_id, desc).removeClass('hide');
114
	createRaceRadarChart(race_id);
115
}
116
117
// Used by game_join.php
118
function createRaceRadarChart(race_id) {
119
120
	// Each array key is the race ID
121
	var races = {
122
		2: [[5.2,  10.0, 5.8,  8.1,  5.2],  'Alskant',    '#FF00FF'],
123
		3: [[8.3,  5.0,  10.0, 3.3,  8.3],  'Creonti',    '#FF8000'],
124
		4: [[9.5,  4.9,  9.5,  7.7,  9.5],  'Human',      '#0000FF'],
125
		5: [[8.0,  6.1,  9.7,  10.0, 8.0],  'Ik\'Thorne', '#BFBFFF'],
126
		6: [[8.1,  4.7,  8.8,  4.3,  8.1],  'Salvene',    '#00AA00'],
127
		7: [[10.0, 5.7,  8.7,  9.1,  10.0], 'Thevian',    '#800000'],
128
		8: [[7.2, 6.3,   7.9,  6.2,  7.2],  'WQ Human',   '#804040'],
129
		9: [[9.5, 4.9,   8.0,  5.1,  9.5],  'Nijarin',    '#FF8080']
130
	};
131
132
	var data = [
133
		{
134
			type: 'scatterpolar',
135
			r: races[race_id][0],
136
			theta: ['Hunting', 'Trading', 'Combat', 'Utility', 'Hunting'],
137
			fill: 'toself',
138
			name: races[race_id][1],
139
			line: {color: races[race_id][2]},
140
			title: {
141
				text: races[race_id][1]
142
			}
143
		}
144
	];
145
146
	var layout = {
147
		showlegend: true,
148
		polar: {
149
			radialaxis: {
150
				visible: true,
151
				showgrid: true,
152
				range: [0, 10],
153
				color: '#fff',
154
			},
155
			bgcolor: '#111'
156
		},
157
		paper_bgcolor: '#06240E',
158
		font: {
159
			color: '#fff'
160
		},
161
		margin: { l: 170, r: 170, t: 0, b: 0 },
162
		coloraxis: '#000'
163
	};
164
165
	Plotly.newPlot('graphframe', data, layout, {staticPlot: true});
0 ignored issues
show
Bug introduced by
The variable Plotly seems to be never declared. If this is a global, consider adding a /** global: Plotly */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
166
}
167
168
// Used by alliance_create.php and alliance_stat.php
169
function togglePassword(select) {
170
	var showPassword = $(select).val() === "password";
171
	// We need to both toggle the element display (for the user) and toggle the
172
	// disabled property (for the form submission).
173
	if (showPassword) {
174
		$("#password-display").show();
175
	} else {
176
		$("#password-display").hide();
177
	}
178
	$("#password-input").prop("disabled", !showPassword);
179
}
180
181
// Used by message_view.php
182
function toggleScoutGroup(senderID) {
183
	$('#group'+senderID).toggle();
184
}
185